USE [master]
GO
/****** Object:  Database [bd_betting_dt]    Script Date: 29/11/2011 12:09:10 ******/
CREATE DATABASE [bd_betting_dt] ON  PRIMARY
( 
	NAME = N'bd_betting_dt', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\bd_betting_dt.mdf',
	SIZE = 3072KB , 
	MAXSIZE = UNLIMITED, 
	FILEGROWTH = 1024KB )
 LOG ON 
( 
	NAME = N'bd_betting_dt_log', 
	FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\bd_betting_dt_log.ldf',
	SIZE = 1024KB , 
	MAXSIZE = 2048GB , 
	FILEGROWTH = 10%)
GO
ALTER DATABASE [bd_betting_dt] SET COMPATIBILITY_LEVEL = 90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [bd_betting_dt].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [bd_betting_dt] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [bd_betting_dt] SET ANSI_NULLS OFF
GO
ALTER DATABASE [bd_betting_dt] SET ANSI_PADDING OFF
GO
ALTER DATABASE [bd_betting_dt] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [bd_betting_dt] SET ARITHABORT OFF
GO
ALTER DATABASE [bd_betting_dt] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [bd_betting_dt] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [bd_betting_dt] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [bd_betting_dt] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [bd_betting_dt] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [bd_betting_dt] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [bd_betting_dt] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [bd_betting_dt] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [bd_betting_dt] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [bd_betting_dt] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [bd_betting_dt] SET  ENABLE_BROKER
GO
ALTER DATABASE [bd_betting_dt] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [bd_betting_dt] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [bd_betting_dt] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [bd_betting_dt] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [bd_betting_dt] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [bd_betting_dt] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [bd_betting_dt] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [bd_betting_dt] SET  READ_WRITE
GO
ALTER DATABASE [bd_betting_dt] SET RECOVERY SIMPLE
GO
ALTER DATABASE [bd_betting_dt] SET  MULTI_USER
GO
ALTER DATABASE [bd_betting_dt] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [bd_betting_dt] SET DB_CHAINING OFF
GO
USE [bd_betting_dt]
GO

/****** Object:  Table [dbo].[Categoria]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[categoria](
[idCategoria] [int] IDENTITY(1,1) NOT NULL,
[nombre] [varchar](100) NOT NULL,
[descripcion] [varchar](600) NOT NULL,
[empate] [varchar](2) NOT NULL,
[dos_jugadores] [varchar](2) NOT NULL,
[imagenRuta] [varchar](100) NOT NULL,
CONSTRAINT [PK_Categoria] PRIMARY KEY CLUSTERED 
(
	[idCategoria] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[evento]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[evento](
[idEvento] [int] IDENTITY(1,1) NOT NULL,
[nombre] [varchar](100) NOT NULL,
[fechaEvento] [date],
[horaInicioEvento] [time],
[fk_categoria] [int] NOT NULL,
CONSTRAINT [PK_Evento] PRIMARY KEY CLUSTERED 
(
	[idEvento] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO


/****** Object:  Table [dbo].[participante]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[participante](
[idParticipante] [int] IDENTITY(1,1) NOT NULL,
[nombre] [varchar](100) NOT NULL,
[descripcion] [varchar](300) NOT NULL,
CONSTRAINT [PK_Participante] PRIMARY KEY CLUSTERED 
(
	[idParticipante] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[detalle_participante_evento]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[detalle_participante_evento](
[idPe] [int] IDENTITY(1,1) NOT NULL,
[fk_evento] [int] NOT NULL,
[fk_participante] [int] NOT NULL,
[posicionFinal] [int] NOT NULL,
[puntaje] [int] NOT NULL,
[monto_tope] [int] NOT NULL,
CONSTRAINT [PK_Pe] PRIMARY KEY CLUSTERED 
(
	[idPe] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO


/****** Object:  Table [dbo].[Usuario]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Usuario](
[idUsuario] [int] IDENTITY(1,1) NOT NULL,
[aliasUsuario] [varchar](50) NOT NULL,
[claveUsuario] [varchar](50) NOT NULL,
[correoElectronico] [varchar](50) NOT NULL,
CONSTRAINT [PK_Usuario] PRIMARY KEY CLUSTERED 
(
	[idUsuario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[maquina_apuesta]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[maquina_apuesta](
[idMaquina] [int] IDENTITY(1,1) NOT NULL,
[marca] [varchar](50) NOT NULL,
[status] [varchar](50) NOT NULL,
[latitud] [int] NOT NULL,
[longitud] [int] NOT NULL,
[numeroIdentificacion] [varchar](10) NOT NULL,
[descripcion] [varchar](300) NOT NULL,
[rutaImagenMaquina] [varchar](100) NOT NULL,
CONSTRAINT [PK_Maquina] PRIMARY KEY CLUSTERED 
(
	[idMaquina] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[usuario_maquina]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[usuario_maquina](
[fk_usuario] [int] NOT NULL,
[fk_maquina] [int] NOT NULL,
CONSTRAINT [PK_usuario_maquina] PRIMARY KEY CLUSTERED 
(
	[fk_usuario],
	[fk_maquina]
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[apuesta]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[apuesta](
[idApuesta] [int] IDENTITY(1,1) NOT NULL,
[monto] [int] NOT NULL,
[fechaYHoraApuesta] [datetime] NOT NULL,
[fk_maquina_apuesta] [int] NOT NULL,
[fk_participante_evento] [int] NOT NULL,
CONSTRAINT [PK_apuesta] PRIMARY KEY CLUSTERED 
(
	[idApuesta] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[tabla_posicion]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tabla_posicion](
[idTablaPosicion] [int] IDENTITY(1,1) NOT NULL,
[fk_apuesta] [int] NOT NULL,
[fk_detalle_pe] [int] NOT NULL,
CONSTRAINT [PK_tabla_posicion] PRIMARY KEY CLUSTERED 
(
	[idTablaPosicion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO


/****** Object:  Table [dbo].[relacion_pago]    Script Date: 29/11/2011 12:09:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[pago](
[idPago] [int] IDENTITY(1,1) NOT NULL,
[nombre] [varchar](100) NOT NULL,
[valor] [decimal] NOT NULL,
CONSTRAINT [PK_Pago] PRIMARY KEY CLUSTERED 
(
	[idPago] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/*** 		ALTER TABLES			***/

/****** Object:  ForeignKey [fk_categoria_evento]    Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[evento]  WITH CHECK ADD  CONSTRAINT [fk_categoria_evento] FOREIGN KEY([fk_categoria])
REFERENCES [dbo].[categoria] ([idCategoria])
GO
ALTER TABLE [dbo].[evento] CHECK CONSTRAINT [fk_categoria_evento]
GO


/****** Object:  ForeignKey [fk_detalle_participante_evento_evento]    Script Date: 05/28/2011 17:37:19 ******/
ALTER TABLE [dbo].[detalle_participante_evento]  WITH CHECK ADD  CONSTRAINT [fk_detalle_participante_evento_evento] FOREIGN KEY([fk_evento])
REFERENCES [dbo].[evento] ([idEvento])
GO
ALTER TABLE [dbo].[detalle_participante_evento] CHECK CONSTRAINT [fk_detalle_participante_evento_evento]
GO
/****** Object:  ForeignKey [fk_detalle_participante_evento_participante]  Script Date: 05/28/2011 17:37:20 ******/
ALTER TABLE [dbo].[detalle_participante_evento]  WITH CHECK ADD  CONSTRAINT [fk_detalle_participante_evento_participante] FOREIGN KEY([fk_participante])
REFERENCES [dbo].[participante] ([idParticipante])
GO
ALTER TABLE [dbo].[detalle_participante_evento] CHECK CONSTRAINT [fk_detalle_participante_evento_participante]
GO

/****** Object:  ForeignKey [fk_usuario_maquina_usuario]   Script Date: 05/28/2011 17:37:19 ******/
ALTER TABLE [dbo].[usuario_maquina]  WITH CHECK ADD  CONSTRAINT [fk_usuario_maquina_usuario] FOREIGN KEY([fk_usuario])
REFERENCES [dbo].[usuario] ([idUsuario])
GO
ALTER TABLE [dbo].[usuario_maquina] CHECK CONSTRAINT [fk_usuario_maquina_usuario]
GO
/****** Object:  ForeignKey [fk_usuario_maquina_maquina]  Script Date: 05/28/2011 17:37:20 ******/
ALTER TABLE [dbo].[usuario_maquina]  WITH CHECK ADD  CONSTRAINT [fk_usuario_maquina_maquina] FOREIGN KEY([fk_maquina])
REFERENCES [dbo].[maquina_apuesta] ([idMaquina])
GO
ALTER TABLE [dbo].[usuario_maquina] CHECK CONSTRAINT [fk_usuario_maquina_maquina]
GO

/****** Object:  ForeignKey [fk_apuesta_maquina_apuesta]    Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[apuesta]  WITH CHECK ADD  CONSTRAINT [fk_apuesta_maquina_apuesta] FOREIGN KEY([fk_maquina_apuesta])
REFERENCES [dbo].[maquina_apuesta] ([idMaquina])
GO
ALTER TABLE [dbo].[apuesta] CHECK CONSTRAINT [fk_apuesta_maquina_apuesta]
GO

/****** Object:  ForeignKey [fk_apuesta_participante]    Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[apuesta]  WITH CHECK ADD  CONSTRAINT [fk_apuesta_participante] FOREIGN KEY([fk_participante_evento])
REFERENCES [dbo].[participante] ([idParticipante])
GO
ALTER TABLE [dbo].[apuesta] CHECK CONSTRAINT [fk_apuesta_participante] 
GO

/****** Object:  ForeignKey [fk_apuesta_detalle_pe]   Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[apuesta]  WITH CHECK ADD  CONSTRAINT [fk_apuesta_detalle_pe] FOREIGN KEY([fk_participante_evento])
REFERENCES [dbo].[detalle_participante_evento] ([idPe])
GO
ALTER TABLE [dbo].[apuesta] CHECK CONSTRAINT [fk_apuesta_detalle_pe]
GO

/****** Object:  ForeignKey [fk_tabla_posicion_apuesta]    Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[tabla_posicion]  WITH CHECK ADD  CONSTRAINT [fk_tabla_posicion_apuesta] FOREIGN KEY([fk_apuesta])
REFERENCES [dbo].[apuesta] ([idApuesta])
GO
ALTER TABLE [dbo].[tabla_posicion] CHECK CONSTRAINT [fk_tabla_posicion_apuesta] 
GO

/****** Object:  ForeignKey [fk_tabla_posicion_detalle_pe]   Script Date: 29/11/2011 17:37:19 ******/
ALTER TABLE [dbo].[tabla_posicion]  WITH CHECK ADD  CONSTRAINT [fk_tabla_posicion_detalle_pe] FOREIGN KEY([fk_detalle_pe])
REFERENCES [dbo].[detalle_participante_evento] ([idPe])
GO
ALTER TABLE [dbo].[tabla_posicion] CHECK CONSTRAINT [fk_tabla_posicion_detalle_pe]
GO
